package pwd.allen;

import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

/**
 * @author 门那粒沙
 * @create 2021-03-09 22:23
 **/
public class MyInterceptor {

    /**
     * 打印方法的执行时间
     * 注意：@Origin注解别用错成net.bytebuddy.asm.Advice.Origin
     *
     * @param method
     * @param callable
     * @return
     * @throws Exception
     */
    @RuntimeType
    public static Object intercept(@Origin Method method, @SuperCall Callable<?> callable, @AllArguments Object[] allArguments) throws Exception {
//        Long start = System.currentTimeMillis();
//        try {
//            System.out.println("原来方法返回值：" + callable.call());
            return null;
//        } finally {
//            System.out.println(String.format("当前方法%s，用时%sms", method.getName(), (System.currentTimeMillis() - start)));
//        }
    }
}
